package com.im.service.common.smo;

import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.im.MDA;
import com.im.service.common.dao.ICommonDAO;
import com.im.service.common.dao.IFileOperDAO;
import com.im.service.common.dao.IFileQueryDAO;
import com.im.service.dto.BaseException;
import com.im.service.dto.BusiConstParam;
import com.im.service.dto.BusiConstParamVal;
import com.im.service.dto.CodeSeq;
import com.im.service.dto.FileUpload;
import com.im.service.dto.ImplementProject;
import com.im.service.dto.PageQuery;
import com.im.service.dto.PlanProject;
import com.im.service.dto.TabColParam;
import com.im.service.model.FileTempVo;
import com.im.service.projectInfo.dao.IImplementProjQueryDAO;
import com.im.service.projectInfo.smo.IProjectInfoQuerySMO;
import com.im.util.DateUtil;
import com.im.util.ExcelUtil;
import com.im.util.GenerateSequenceUtil;
import com.im.util.JsonUtil;
import com.im.util.ListUtil;
import com.im.util.ReturnsUtil;
import com.im.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONNull;
import net.sf.json.JSONObject;


//@Profile("dev")
//@Configuration
//@Service
public class CommonDevSMOImpl implements ICommonSMO {


	@Autowired
	private ICommonDAO commonDAO;
	@Autowired
	private IFileQueryDAO fileQueryDAO;
	@Autowired
	private IFileOperDAO fileOperDAO;
    @Autowired
    private IProjectInfoQuerySMO projectInfoQuerySMO;
    @Autowired
    private IImplementProjQueryDAO implementProjQueryDAO;
	@Autowired
	ApplicationContext context;
	private static final Logger logger = LogManager.getLogger(CommonDevSMOImpl.class);


	@Override
	public void putValueToRedis(String key, Object value, Long expireTime) {
		logger.debug("=== dev no redis...");
	}

	@Override
	public Object getValueFromRedis(String key) {
		logger.debug("=== dev no redis...");
		return null;
	}

	@Override
	public List<TabColParam> queryTabColParam(Map<String, Object> param) throws Exception {	
		return commonDAO.queryTabColParam(param);
	}

	@Override
	public PageQuery<BusiConstParam> queryBusiConstByCond(JSONObject jsonObject) {
		if(jsonObject.containsKey("constParamName") && "".equals(jsonObject.getString("constParamName"))){
			jsonObject.remove("constParamName");
		}
		if(!jsonObject.containsKey("statusCd")){
			jsonObject.element("statusCd",10);
		}
		//设置分页
		PageQuery<BusiConstParam> page;
		if(jsonObject.containsKey("pageInfo")){
			page = JsonUtil.jsonToBean(jsonObject.getString("pageInfo"),PageQuery.class);
		}else{
			page = new PageQuery<>();
		}
		PageHelper.startPage(page.getPageNumber(), page.getPageSize());
		List<BusiConstParam> list= commonDAO.queryBusiConstByCond(jsonObject);
		page.setRows(list);
		page.setTotalPages(((Page<BusiConstParam>)list).getPages());
		page.setTotal(((Page<BusiConstParam>) list).getTotal());
		return page;
	}

	@Override
	public List<?> queryBusiConstValByCond(JSONObject jsonObject) {
		List<BusiConstParamVal> busiConstParamVals = commonDAO.queryBusiConstValByCond(jsonObject);
		//文档模板
		if(jsonObject.containsKey("constParamCode") && "DOC_TEMP_TYPE".equals(jsonObject.getString("constParamCode"))){
			//加载文档详细信息
			List<String> uploadIds = new ArrayList<>();
			for(BusiConstParamVal busiConstParamVal : busiConstParamVals){
				uploadIds.add(busiConstParamVal.getParamValValue());
			}

			List<FileUpload> fileUploads = null;
			if(uploadIds.size() > 0){
				//查询文档信息
				Map<String,Object> param = new HashMap<>();
				param.put("uploadIds",uploadIds);
				fileUploads = fileQueryDAO.queryFileUploadsByCond(param);
			}

			//组装
			List<FileTempVo> fileTempVos = new ArrayList<>();
			for(BusiConstParamVal busiConstParamVal : busiConstParamVals){
				FileTempVo fileTempVo = new FileTempVo();
				fileTempVo.setParamValId(busiConstParamVal.getParamValId());
				fileTempVo.setParamValName(busiConstParamVal.getParamValName());
				fileTempVo.setParamValValue(busiConstParamVal.getParamValValue());
				if(busiConstParamVal.getParamValValue() != null
						&& !"".equals(busiConstParamVal.getParamValValue())
						&& fileUploads != null){
					//设置文档
					for(FileUpload fileUpload : fileUploads){
						if(fileUpload.getUploadObjId().equals(busiConstParamVal.getParamValId())){
							fileTempVo.setUploadDate(fileUpload.getUploadDate());
							fileTempVo.setFilePath(fileUpload.getFilePath());
							fileTempVo.setFileSuffix(fileUpload.getFileSuffix());
							fileTempVo.setUploadId(fileUpload.getUploadId());
							fileTempVo.setUploadName(fileUpload.getUploadName());
							fileTempVo.setUploadObjId(fileUpload.getUploadObjId());
							fileTempVo.setUploadSize(fileUpload.getUploadSize());
							fileTempVo.setDescription(fileUpload.getDescription());
							break;
						}

					}
				}
				fileTempVos.add(fileTempVo);
			}
			return fileTempVos;
		}else{
			return busiConstParamVals;
		}
	}

	@Override
	public void saveOrUpdateBusiConst(JSONObject jsonObject) {
		//
		String constParamId =  null;
		if(jsonObject.containsKey("busiConstParam")){

			BusiConstParam busiConstParam = (BusiConstParam) JsonUtil.jsonstrToBeanObj(jsonObject.getString("busiConstParam"),BusiConstParam.class);

			if("add".equals(busiConstParam.getOperType())){
				constParamId = UUID.randomUUID().toString();
				busiConstParam.setConstParamId(constParamId);
				busiConstParam.setStatusCd(10);
				commonDAO.saveBusiConst(busiConstParam);

			}
			if("modify".equals(busiConstParam.getOperType())){
				if(busiConstParam.getConstParamId() != null){
					commonDAO.updateBusiConst(busiConstParam);
				}
			}
			if("del".equals(busiConstParam.getOperType())){
				if(busiConstParam.getConstParamId() != null){
					busiConstParam.setStatusCd(20);
					commonDAO.updateBusiConst(busiConstParam);
				}
			}


		}
		if(jsonObject.containsKey("busiConstParamVals")){
			JSONArray jsonArray = jsonObject.getJSONArray("busiConstParamVals");
			for(int i=0;i <jsonArray.size(); i++){
				BusiConstParamVal busiConstParamVal = (BusiConstParamVal) JsonUtil.jsonstrToBeanObj(jsonArray.getJSONObject(i).toString(),BusiConstParamVal.class);

				if("add".equals(busiConstParamVal.getOperType())){
					if(busiConstParamVal.getConstParamId() == null || "".equals(busiConstParamVal.getConstParamId())){
						busiConstParamVal.setConstParamId(constParamId);
					}
					busiConstParamVal.setParamValId(UUID.randomUUID().toString());
					busiConstParamVal.setStatusCd(10);
					commonDAO.saveBusiConstVal(busiConstParamVal);
				}
				if("modify".equals(busiConstParamVal.getOperType())){
					if(busiConstParamVal.getParamValId() !=  null){
						commonDAO.updateBusiConstVal(busiConstParamVal);
					}

				}
				if("del".equals(busiConstParamVal.getOperType())){
					if(busiConstParamVal.getParamValId() != null){
						busiConstParamVal.setStatusCd(20);
						commonDAO.updateBusiConstVal(busiConstParamVal);
					}

				}
			}

		}
		if(jsonObject.containsKey("consList")){
			String batchOperType = jsonObject.getString("batchOperType");
			List<String> consList = (List<String>) jsonObject.get("consList");
			if(null != consList && consList.size() > 0){

				for(String consId : consList){
					BusiConstParam busiConstParam = new BusiConstParam();
					if("batchdel".equals(batchOperType)){
						busiConstParam.setStatusCd(20);
					}
					if("batcheff".equals(batchOperType)){
						busiConstParam.setStatusCd(10);
					}
					busiConstParam.setConstParamId(consId);
					commonDAO.updateBusiConst(busiConstParam);
				}
			}

		}

	}

	@Override
	public void saveOrUpdateFileTemp(JSONObject jsonObject) {

		FileUpload fileUpload = (FileUpload) JsonUtil.jsonstrToBeanObj(jsonObject.toString(),FileUpload.class);

		//保存文件信息
		if(fileUpload.getOperType() != null
				&&fileUpload.getOperType().equals("add")){

			String uploadId = UUID.randomUUID().toString();
			fileUpload.setUploadId(uploadId);
			fileOperDAO.saveFileUpload(fileUpload);

			BusiConstParamVal busiConstParamVal = new BusiConstParamVal();
			busiConstParamVal.setParamValId(fileUpload.getUploadObjId());
			busiConstParamVal.setParamValValue(uploadId);
			commonDAO.updateBusiConstVal(busiConstParamVal);

		}else if(fileUpload.getOperType() != null
				&&fileUpload.getOperType().equals("del")){
			BusiConstParamVal busiConstParamVal = new BusiConstParamVal();
			busiConstParamVal.setParamValId(fileUpload.getUploadObjId());
			busiConstParamVal.setParamValValue("");
			commonDAO.updateBusiConstVal(busiConstParamVal);
		}else if(fileUpload.getOperType() != null
				&&fileUpload.getOperType().equals("mod")){
			fileOperDAO.updateFileUpload(fileUpload);
		}
	}

	/**
	 * 一个通用的方法生产编码如合同编号、采购计划编号、项目编号、资金计划编号、投资资金编号等等。 规则是：
	 * <p>1.从t_busi_const_param中获取COST_PARAM_CODE='PRE_CODE'
	 * <p>2.从t_busi_const_param_val中获取对应的前缀A 
	 * <p>3.A+YYYYMMDD+6位序列号
	 * @throws Exception 
	 */
	@Override
	public String querySeq(String tableName) throws Exception {
		
		// 1.从t_busi_const_param中获取COST_PARAM_CODE='PRE_CODE'
		Map<String,Object> inMap = new HashMap<String,Object>();
		inMap.put("constParamCode",MDA.PRE_CODE);
		List<BusiConstParam> list= commonDAO.queryBusiConstByCond(inMap);
		if(ListUtil.isListEmpty(list)){
			throw new Exception("查询t_busi_const_param 数据为空！");
		}
		BusiConstParam bcp = list.get(0);
		inMap.clear();
		
		// 2.从t_busi_const_param_val中获取对应的前缀A 
		String constParamId = bcp.getConstParamId();
		inMap.put("constParamId", constParamId);
		inMap.put("paramValValue", MDA.TABLE_TYPE_SEQ.get(tableName));
		List<BusiConstParamVal> listVal = commonDAO.queryBusiConstValByCond(inMap);
		if(ListUtil.isListEmpty(listVal)){
			throw new Exception("查询t_busi_const_param_val 前缀 数据为空！");
		}
		BusiConstParamVal bcpv = listVal.get(0);
		String fax = bcpv.getParamValName();
		
		// 3.A+YYYYMMDD+6位序列号
		StringBuffer sb = new StringBuffer();
		sb.append(fax);
		String seq = "";
		
		if(MDA.IS_FROM_DB){
			// (1)	获取 6位序列 ； 从t_code_seq 表 取 序列的最大值  code_seq_val
			String seqName = tableName+"_SEQ";
			inMap.put("codeSeqName", seqName);
			List<CodeSeq> seqValList = commonDAO.queryCodeSeq(inMap);
			if(ListUtil.isListEmpty(seqValList) || seqValList.size()!=1){
				throw new Exception("查询t_code_seq 序列 数据异常！");
			}
			CodeSeq codeSeq = seqValList.get(0);
			Long val = codeSeq.getCodeSeqVal()+1;
			Format format = new SimpleDateFormat("yyyyMMdd");
			seq =format.format(new Date()) + StringUtil.leftFillStr(3, val, "0");
			// (2) 更新 t_code_seq 表的 code_seq_val
			codeSeq.setCodeSeqVal(val);
			updateCodeSeq(codeSeq);

		} else {
			seq = GenerateSequenceUtil.getLengthSeq();
		}
		sb.append(seq);
		return sb.toString();
	}

	@Override
	public void updateCodeSeq(CodeSeq codeSeq) throws Exception {
		commonDAO.updateCodeSeq(codeSeq);
	}

	@Override
	public void getExportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			String errorMsg = "获取入参时：";
			String json = request.getParameter("json");
			if (json.equals(new String(json.getBytes("iso8859-1"), "iso8859-1"))) {
				json = new String(json.getBytes("iso8859-1"), "utf-8");
			}
			JSONObject jsonObject = JSONObject.fromObject(json);
			String param = JsonUtil.getNotNullStringFromJSON(jsonObject, "param", errorMsg);
			String classes = JsonUtil.getNotNullStringFromJSON(jsonObject, "classes", errorMsg);
			classes = "com.im.controller." + classes;
			String method = JsonUtil.getNotNullStringFromJSON(jsonObject, "method", errorMsg);
			String fileName = JsonUtil.getNotNullStringFromJSON(jsonObject, "fileName", errorMsg);
			JSONObject title = jsonObject.getJSONObject("title");
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/x-download");
			fileName = URLEncoder.encode(fileName + DateUtil.getNowDefault() + ".xlsx", "UTF-8");
			response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/x-download");
			XSSFWorkbook wb = new XSSFWorkbook();
			XSSFSheet sheet = wb.createSheet("sheet1");
			XSSFRow titlerow = sheet.createRow(0);
			XSSFRow subtitlerow = null;
			int rownum = 1;
			if (json.indexOf("$") > -1) {
				subtitlerow = sheet.createRow(1);
				rownum = 2;
			}
			XSSFCellStyle titlecellStyle = wb.createCellStyle();
			titlecellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
			// 标题行
			Iterator titleiterator = title.values().iterator();
			if (json.indexOf("$") > -1) {
				String headtitle = null;
				int num = -1;
				for (int i = 0; i < title.size(); i++) {
					String item = (String) titleiterator.next();
					if (item.indexOf("$") > -1) {
						if (headtitle == null) {
							headtitle = item.split("\\$")[1];
							String subheadtitle = item.split("\\$")[0];
							num = json.split("\\$" + headtitle.replace("*", "\\*")).length - 2;
							CellRangeAddress cellRangeAddresS = new CellRangeAddress(0, 0, i, i + num);
							sheet.addMergedRegion(cellRangeAddresS);
							XSSFCell titlecell = titlerow.createCell(i);
							titlecell.setCellStyle(titlecellStyle);
							titlecell.setCellValue(headtitle);
							XSSFCell subtitlecell = subtitlerow.createCell(i);
							subtitlecell.setCellStyle(titlecellStyle);
							subtitlecell.setCellValue(subheadtitle);
							num--;
							sheet.setColumnWidth(i, 256 * 10 + 184);
						} else {
							String subheadtitle = item.split("\\$")[0];
							XSSFCell subtitlecell = subtitlerow.createCell(i);
							subtitlecell.setCellStyle(titlecellStyle);
							subtitlecell.setCellValue(subheadtitle);
							num--;
							if (num == -1) {
								headtitle = null;
							}
							sheet.setColumnWidth(i, 256 * 10 + 184);
						}

					} else {
						CellRangeAddress cellRangeAddresS = new CellRangeAddress(0, 1, i, i);
						sheet.addMergedRegion(cellRangeAddresS);
						XSSFCell titlecell = titlerow.createCell(i);
						titlecell.setCellStyle(titlecellStyle);
						titlecell.setCellValue(item);
						sheet.setColumnWidth(i, 256 * 20 + 184);
					}
				}
			} else {
				for (int i = 0; i < title.size(); i++) {
					XSSFCell titlecell = titlerow.createCell(i);
					titlecell.setCellValue((String) titleiterator.next());
					sheet.setColumnWidth(i, 256 * 10 + 184);
				}
			}
			Class smo = Class.forName(classes);
			java.lang.reflect.Method m = smo.getMethod(method, String.class);
			Field[] fileds = smo.getDeclaredFields();
			Object obj = smo.newInstance();
			for (Field f : fileds) {
				if (f.isAnnotationPresent(Autowired.class)) {
					// 基于类型注入
					Class<?> c = f.getType();
					Object value = context.getBean(c);
					// 允许访问private字段
					f.setAccessible(true);
					// 把引用对象注入属性
					f.set(obj, value);
				}
			}
			Object result = m.invoke(obj, param);
			JSONObject resultJson = JSONObject.fromObject(result.toString());
			JSONArray resultlist = resultJson.getJSONObject("result").getJSONArray("rows");
			Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
			for (int i = 0; i < resultlist.size(); i++) {
				XSSFRow row = sheet.createRow(i + rownum);
				JSONObject item = resultlist.getJSONObject(i);
				Iterator keys = title.keys();
				JSONArray fundDetails = null;
				int j = 0;
				while (keys.hasNext()) {
					Boolean flag = false;
					XSSFCell cell = row.createCell(j);
					String key = (String) keys.next();
					String value = "";
					if(key.indexOf(".")>-1){
						if (key.indexOf("fundDetailVo.") > -1) {
							if (fundDetails == null)
							fundDetails = item.getJSONArray("fundDetailVo");
							String[] childKeys = key.split("\\.");
							String fundkey = childKeys[1];
							String valueKey = childKeys[2];
							for (int k = 0; k < fundDetails.size(); k++) {
								JSONObject funds = fundDetails.getJSONObject(k);
								if (fundkey.equals(funds.getString("type"))) {
									value = funds.getString(valueKey);
									break;
								}
							}
						} else {
							String[] childKeys = key.split("\\.");
							JSONObject child = item.getJSONObject(childKeys[0]);
							value = child.get(childKeys[1]) + "";
						}
					}else{
						if ((Object) item.get(key) == null || JSONNull.getInstance().equals(item.get(key))) {
							value = "";
						} else {
							value = item.get(key) + "";
						}
					}

					if (p.matcher(value).find() && value.length() > 20) {
						int size = value.length() / 10;
						if (value.length() % 10 != 0) {
							size += 1;
						}
						List<String> list = new ArrayList<String>();
						for (int index = 0; index < size; index++) {
							String childStr = substring(value, index * 10, (index + 1) * 10);
							list.add(childStr);
						}
						StringBuilder sBuilder = new StringBuilder();
						for (int k = 0; k < list.size(); k++) {
							sBuilder.append(list.get(k));
							if (k != list.size() - 1) {
								sBuilder.append("\r\n");
							}
						}
						value = sBuilder.toString();
						flag = true;
					}
					if (StringUtil.isBlank(value)) {
						cell.setCellValue("");
					} else {
						if (flag) {
							XSSFCellStyle cellStyle = wb.createCellStyle();
							cellStyle.setWrapText(true);
							cell.setCellStyle(cellStyle);
							cell.setCellValue(new XSSFRichTextString(value));
							sheet.setColumnWidth(i, 256 * 20 + 184);
						} else {
							cell.setCellValue(value);
						}
					}
					j++;
				}
			}
			OutputStream out = response.getOutputStream();
			wb.write(out);
			out.close();
		} catch (BaseException e) {
			if (logger.isErrorEnabled()) {
				logger.error(e.getStackTrace());
			}
			return;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
				return;
			}
			return;
		}
	}

	public static String substring(String str, int f, int t) {
		if (f > str.length())
			return null;
		if (t > str.length()) {
			return str.substring(f, str.length());
		} else {
			return str.substring(f, t);
		}
	}

	@Override
	public String querySeqForRule(String seqType, String pCode) throws Exception {
		Map<String,Object> inMap = new HashMap<String,Object>();
		Integer cnt = 0;
		String tableName =  MDA.SEQ_TYPE.get(seqType);
		if(StringUtil.isEmpty(tableName)){
			throw new Exception("获取序列时，序列类型["+seqType+"]错误！");
		}
		String code="";
        if("5".equals(seqType)){
            inMap.put("table_name_b", "t_plan_project");
            inMap.put("b_code_name", "plan_proj_class");
            inMap.put("b_code", pCode);
            Integer val = commonDAO.queryTableCount(inMap);
            String seq = pCode + "-" + StringUtil.leftFillStr(3, val+1, "0");
            return seq;

        } else if("1".equals(seqType)){
            PlanProject planProject = new PlanProject();
            planProject.setPlanProjId(pCode);
            PlanProject retPlanProject = projectInfoQuerySMO.queryPlanProjDetail(planProject);
            if(retPlanProject == null){
                throw new Exception("查询 ID["+pCode+"]数据为空！");
            }
            // 实施项目序列
            inMap.put("table_name_a", MDA.SEQ_TYPE.get(seqType));
            inMap.put("col_name", "PLAN_PROJ_ID");
            inMap.put("col_val", pCode);
        } else {
            ImplementProject impleProj = new ImplementProject();
            impleProj.setImpleProjId(pCode);
            inMap.put("impleProj", impleProj);
            List<Map<String, Object>> retList = implementProjQueryDAO.queryImpleProjCode(inMap);
            if (ListUtil.isListEmpty(retList)) {
                throw new Exception("查询 ID[" + pCode + "]数据为空！");
            }

            code = String.valueOf(retList.get(0).get("imple_proj_code"));

            if("3".equals(seqType)) {
                 // 标书序列
                 //inMap.put("col_name", "rela_obj_id");
				inMap.put("col_name", "IMPLE_PROJ_ID");
             }else {
                // 采购计划序列  // 合同序列
                inMap.put("col_name", "IMPLE_PROJ_ID");
            }

            inMap.put("table_name_a", MDA.SEQ_TYPE.get(seqType));
            inMap.put("col_val",pCode);
        }

//		// 查询 编码是否存在
//		cnt = commonDAO.queryTableCount(inMap);
//		if(cnt<=0){
//			throw new Exception("查询 ID["+pCode+"]数据为空！");
//		}
		Integer val = commonDAO.getSeqForRule(inMap);
		String seq = code + "-" + StringUtil.leftFillStr(3, val + 1, "0");
		return seq;



	}

	/**
	 * 解析导入的excel
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@Override
	public String saveOrUpdateExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject ret =  new JSONObject();
		ret.element("resultCode","0");
		ret.element("resultMsg","上传成功!");

		try {
			//导入的文件类型
			//1,合同
			//2,采购计划
			//3,实施项目_文档信息
			//4,实施项目
			//5,招投标项目
			//6,规划项目
			String excelType = request.getParameter("excelType");
			MultipartRequest multipartRequest=(MultipartRequest) request;
			MultipartFile excelFile=multipartRequest.getFile("excelFile");
			if(excelFile!=null){
				String fileName = excelFile.getOriginalFilename();
				String fileSufix = fileName.substring(fileName.lastIndexOf("."),fileName.length());

				List<List<String>> datas = null;
				if(".xls".equals(fileSufix)){
					datas = ExcelUtil.readXls(excelFile.getInputStream());
				}else{
					datas = ExcelUtil.readXlsx(excelFile.getInputStream());
				}
				if(datas != null && datas.size() > 0){

					if("1".equals(excelType)){
						//1,合同


					}else if("2".equals(excelType)){
						//2,采购计划


					}else if("3".equals(excelType)){
						//3,实施项目_文档信息


					}else if("4".equals(excelType)){
						//4,实施项目


					}else if("5".equals(excelType)){
						//5,招投标项目

					}else if("6".equals(excelType)){
						//6,规划项目


					}
				}
			}else{
				ret.element("resultCode" ,"-1");
				ret.element("resultMsg","文件为空!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ReturnsUtil.returnException("excel导入失败！",e).toString();
		}

		return ret.toString();
	}

}
